/*
 * BeamStack.java
 *
 * Created on July 31, 2006, 4:02 PM
 *
 */

package galronnlp.util;

/**
 *
 * @author Daniel A. Galron
 */
public abstract class BeamStack {
    
    protected PriorityQueue<Scorable> stack = new PriorityQueue<Scorable>();
    
    private int elementNumber = 100;
    private double beamFactor = 1.0;
    private double highest = 1.0;
    
    public BeamStack() {
        
    }
    
    public void resort() {
        PriorityQueue<Scorable> resort = new PriorityQueue<Scorable>();
        while(stack.size() > 0) {
            resort.insort(stack.removeHighest());
        }
        stack = resort;
    }
    
    public boolean contains(Scorable o) {
        return stack.contains(o);
    }
    
    public BeamStack(BeamStack bs) {
        this.stack = new PriorityQueue<Scorable>(bs.stack);
    }
    
    public int size() {
        return stack.size();
    }
    
    /** Creates a new instance of BeamStack */
    public BeamStack(double b, int e) {
        this.elementNumber = e;
        this.beamFactor = b;
    }
    
    public boolean push(Scorable o) {
        if(toAdd(o)) {
            stack.push(o);
            return true;
        }
        return false;
    }
    
    public Scorable getHighest() {
        return stack.getHighest();
    }
    
    public Scorable pop() {
        return stack.pop();
    }
    
    public abstract boolean toAdd(Scorable o);
    
}
